package albert3d.gui;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.*;
import java.io.IOException;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class Menu extends JPanel {

	
	JTabbedPane tabs = new JTabbedPane();
	private JPanel panelFile = new JPanel();
	private JPanel panelEdit = new JPanel();
	private JPanel panelInfo = new JPanel();
	private JPanel panelHelp = new JPanel();
	
	JButton przyciskImportPhotos = new JButton();
	JButton przyciskThreshold = new JButton();
	JButton przyciskDesignatePoints = new JButton();	
	JButton przyciskCreatePolygons = new JButton();
	JButton przyciskSave = new JButton();
	JButton przyciskClear = new JButton();
	JButton openAction = new JButton();
	JButton newAction = new JButton();
	JButton saveAction = new JButton();
	private JButton importObj = new JButton();
	private JButton exportObj = new JButton();
	
	private JPanel xRotateSliderToolsPanel = new JPanel();
	private JSlider xRotateSlider = new JSlider(JSlider.HORIZONTAL, -360, 360, 0);
	private JButton xRotateSliderLeftButton = new JButton("<");
	private JButton xRotateSliderRightButton = new JButton(">");
	private JLabel xRotateSliderValue = new JLabel("    X: " + new Integer(xRotateSlider.getValue()).toString());
	
	private JPanel yRotateSliderToolsPanel = new JPanel();
	private JSlider yRotateSlider = new JSlider(JSlider.HORIZONTAL, -360, 360, 0);
	private JButton yRotateSliderLeftButton = new JButton("<");
	private JButton yRotateSliderRightButton = new JButton(">");
	private JLabel yRotateSliderValue = new JLabel("    Y: " + new Integer(yRotateSlider.getValue()).toString());
	
	private JPanel zRotateSliderToolsPanel = new JPanel();
	private JSlider zRotateSlider = new JSlider(JSlider.HORIZONTAL, -360, 360, 0);
	private JButton zRotateSliderLeftButton = new JButton("<");
	private JButton zRotateSliderRightButton = new JButton(">");
	private JLabel zRotateSliderValue = new JLabel("    Z: " + new Integer(zRotateSlider.getValue()).toString());
	
	private JPanel xTranslateSliderToolsPanel = new JPanel();
	private JSlider xTranslateSlider = new JSlider(JSlider.HORIZONTAL, -200, 200, 0);
	private JButton xTranslateSliderLeftButton = new JButton("<");
	private JButton xTranslateSliderRightButton = new JButton(">");
	private JLabel xTranslateSliderValue = new JLabel("    X: " + new Float(xTranslateSlider.getValue()/10.0f).toString());
	
	private JPanel yTranslateSliderToolsPanel = new JPanel();
	private JSlider yTranslateSlider = new JSlider(JSlider.HORIZONTAL, -200, 200, 0);
	private JButton yTranslateSliderLeftButton = new JButton("<");
	private JButton yTranslateSliderRightButton = new JButton(">");
	private JLabel yTranslateSliderValue = new JLabel("    Y: " + new Float(yTranslateSlider.getValue()/10.0f).toString());
	
	private JPanel zTranslateSliderToolsPanel = new JPanel();
	private JSlider zTranslateSlider = new JSlider(JSlider.HORIZONTAL, -200, 200, 0);
	private JButton zTranslateSliderLeftButton = new JButton("<");
	private JButton zTranslateSliderRightButton = new JButton(">");
	private JLabel zTranslateSliderValue = new JLabel("    Z: " + new Float(zTranslateSlider.getValue()/10.0f).toString());
	
	private JPanel scaleSliderToolsPanel = new JPanel();
	private JSlider scaleSlider = new JSlider(JSlider.HORIZONTAL, 1, 1000, 10);
	private JButton scaleSliderLeftButton = new JButton("<");
	private JButton scaleSliderRightButton = new JButton(">");
	private JLabel scaleSliderValue = new JLabel("    X: " + new Float(scaleSlider.getValue()/10.0f).toString());
	
	private JPanel polyModePanel = new JPanel();
	private JPanel faceModePanel = new JPanel();
	private JButton polyModePointButton = new JButton("Point");
	private JButton polyModeLineButton = new JButton("Line");
	private JButton polyModeFillButton = new JButton("Fill");
	private JButton faceModeFrontButton = new JButton("Line Fill");
	private JButton faceModeBackButton = new JButton("Point Fill");
	private JButton faceModeFrontAndBackButton = new JButton("Clear");
	private JButton resetCameraButton = new JButton("Reset Camera");
	private JButton resetObjectButton = new JButton("Reset Object");
	private JLabel dataLines[] = new JLabel[23];
	private JLabel helpLabel = new JLabel();
	private String helpText =
			"<html>" +
			"<h1>3D Photo</h1>" + "<br />" +
			"" + "<br />" +
			"Programming:" + "<br />" +
			"- Artur Lewandowski" + "<br />" +
			"- Robert Gralicki" + "<br />" +
			"- Bartosz Durda" + "<br />" +
			"" + "<br />" +
			"Documentation & Graphic Design:" + "<br />" +
			"- Mariusz Pipczyński" + "<br />" +
			"" + "<br />" +
			"Website:" + "<br />" +
			"- Mariusz Józwiak" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"" + "<br />" +
			"Home Page:  " + "<a href=\"http://www.3d-photo.pl/\">www.3d-photo.pl</a>" + "<br />" +
			"</html>";
	
	
	Progowanie progowanie = new Progowanie();
	WyznaczaniePunktow wp = new WyznaczaniePunktow();
	ZapisOBJ saveObj = new ZapisOBJ();
	Faces faces;
	
	public JButton getImportObjButton() {
		return importObj;
	}
	
	public JSlider getXRotateSlider() {
		return xRotateSlider;
	}
	
	public JSlider getYRotateSlider() {
		return yRotateSlider;
	}
	
	public JSlider getZRotateSlider() {
		return zRotateSlider;
	}
	
	public JSlider getXTranslateSlider() {
		return xTranslateSlider;
	}
	
	public JSlider getYTranslateSlider() {
		return yTranslateSlider;
	}
	
	public JSlider getZTranslateSlider() {
		return zTranslateSlider;
	}
	
	public JSlider getScaleSlider() {
		return scaleSlider;
	}
	
	public JButton getPolyModePointButton() {
		return polyModePointButton;
	}
	
	public JButton getPolyModeLineButton() {
		return polyModeLineButton;
	}
	
	public JButton getPolyModeFillButton() {
		return polyModeFillButton;
	}
	
	public JButton getFaceModeBackButton() {
		return faceModeBackButton;
	}
	
	public JButton getFaceModeFrontButton() {
		return faceModeFrontButton;
	}
	
	public JButton getFaceModeFrontAndBackButton() {
		return faceModeFrontAndBackButton;
	}
	
	public JButton getResetCameraButton() {
		return resetCameraButton;
	}
	
	public JButton getResetObjectButton() {
		return resetObjectButton;
	}
	
	public JLabel[] getDataLines() {
		return dataLines;
	}

	public Menu(final OknoGlowne oknoGlowne) {

		/* Przedyskutowac i poprawic */
		tabs.addTab("File", panelFile);
		tabs.addTab("Edit", panelEdit);
		tabs.addTab("Data", panelInfo);
		tabs.addTab("Help", panelHelp);
		

		panelFile.setLayout(new GridLayout(0, 1));
		panelEdit.setLayout(new GridLayout(0, 1));
		panelInfo.setLayout(new GridLayout(0, 1));
		
		importObj.setText("Import OBJ");
		importObj.setPreferredSize(new Dimension(200, 20));
		panelEdit.add(importObj);
		
		exportObj.setText("Export OBJ");
		exportObj.setPreferredSize(new Dimension(200, 20));
		panelEdit.add(exportObj);
		panelEdit.add(new JLabel("ROTATE"));
		
		xRotateSliderLeftButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(xRotateSlider.getValue()>-360)
					xRotateSlider.setValue(xRotateSlider.getValue()-1);
			}
		});
		
		xRotateSliderRightButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(xRotateSlider.getValue()<360)
					xRotateSlider.setValue(xRotateSlider.getValue()+1);
			}
		});
		
		xRotateSlider.setToolTipText("X");
		xRotateSliderToolsPanel.setPreferredSize(new Dimension(200, 20));
		xRotateSliderToolsPanel.setLayout(new GridLayout(1, 3));
		xRotateSliderToolsPanel.add(xRotateSliderLeftButton);
		xRotateSliderToolsPanel.add(xRotateSliderRightButton);
		xRotateSliderToolsPanel.add(xRotateSliderValue);
		panelEdit.add(xRotateSlider);
		panelEdit.add(xRotateSliderToolsPanel);
		
		xRotateSlider.addChangeListener(new ChangeListener() {
			
			@Override
			public void stateChanged(ChangeEvent e) {
				xRotateSliderValue.setText("    X: " + new Integer(xRotateSlider.getValue()).toString());
			}
		});
		
		yRotateSliderLeftButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(yRotateSlider.getValue()>-360)
					yRotateSlider.setValue(yRotateSlider.getValue()-1);
			}
		});
		
		yRotateSliderRightButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(yRotateSlider.getValue()<360)
					yRotateSlider.setValue(yRotateSlider.getValue()+1);
			}
		});
		
		yRotateSlider.setToolTipText("Y");
		yRotateSliderToolsPanel.setPreferredSize(new Dimension(200, 20));
		yRotateSliderToolsPanel.setLayout(new GridLayout(1, 3));
		yRotateSliderToolsPanel.add(yRotateSliderLeftButton);
		yRotateSliderToolsPanel.add(yRotateSliderRightButton);
		yRotateSliderToolsPanel.add(yRotateSliderValue);
		panelEdit.add(yRotateSlider);
		panelEdit.add(yRotateSliderToolsPanel);
		
		yRotateSlider.addChangeListener(new ChangeListener() {
			
			@Override
			public void stateChanged(ChangeEvent e) {
				yRotateSliderValue.setText("    Y: " + new Integer(yRotateSlider.getValue()).toString());
			}
		});
		
		zRotateSliderLeftButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(zRotateSlider.getValue()>-360)
					zRotateSlider.setValue(zRotateSlider.getValue()-1);
			}
		});
		
		zRotateSliderRightButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(zRotateSlider.getValue()<360)
					zRotateSlider.setValue(zRotateSlider.getValue()+1);
			}
		});
		
		zRotateSlider.setToolTipText("Z");
		zRotateSliderToolsPanel.setPreferredSize(new Dimension(200, 20));
		zRotateSliderToolsPanel.setLayout(new GridLayout(1, 3));
		zRotateSliderToolsPanel.add(zRotateSliderLeftButton);
		zRotateSliderToolsPanel.add(zRotateSliderRightButton);
		zRotateSliderToolsPanel.add(zRotateSliderValue);
		panelEdit.add(zRotateSlider);
		panelEdit.add(zRotateSliderToolsPanel);
		
		zRotateSlider.addChangeListener(new ChangeListener() {
			
			@Override
			public void stateChanged(ChangeEvent e) {
				zRotateSliderValue.setText("    Z: " + new Integer(zRotateSlider.getValue()).toString());
			}
		});
		
		panelEdit.add(new JLabel("TRANSLATE"));
		
		xTranslateSliderLeftButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(xTranslateSlider.getValue()>-200)
					xTranslateSlider.setValue(xTranslateSlider.getValue()-1);
			}
		});
		
		xTranslateSliderRightButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(xTranslateSlider.getValue()<200)
					xTranslateSlider.setValue(xTranslateSlider.getValue()+1);
			}
		});
		
		xTranslateSlider.setToolTipText("X");
		xTranslateSliderToolsPanel.setPreferredSize(new Dimension(200, 20));
		xTranslateSliderToolsPanel.setLayout(new GridLayout(1, 3));
		xTranslateSliderToolsPanel.add(xTranslateSliderLeftButton);
		xTranslateSliderToolsPanel.add(xTranslateSliderRightButton);
		xTranslateSliderToolsPanel.add(xTranslateSliderValue);
		panelEdit.add(xTranslateSlider);
		panelEdit.add(xTranslateSliderToolsPanel);
		
		xTranslateSlider.addChangeListener(new ChangeListener() {
			
			@Override
			public void stateChanged(ChangeEvent e) {
				xTranslateSliderValue.setText("    X: " + new Float(xTranslateSlider.getValue()/10.0f).toString());
			}
		});
		
		yTranslateSliderLeftButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(yTranslateSlider.getValue()>-200)
					yTranslateSlider.setValue(yTranslateSlider.getValue()-1);
			}
		});
		
		yTranslateSliderRightButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(yTranslateSlider.getValue()<200)
					yTranslateSlider.setValue(yTranslateSlider.getValue()+1);
			}
		});
		
		yTranslateSlider.setToolTipText("Y");
		yTranslateSliderToolsPanel.setPreferredSize(new Dimension(200, 20));
		yTranslateSliderToolsPanel.setLayout(new GridLayout(1, 3));
		yTranslateSliderToolsPanel.add(yTranslateSliderLeftButton);
		yTranslateSliderToolsPanel.add(yTranslateSliderRightButton);
		yTranslateSliderToolsPanel.add(yTranslateSliderValue);
		panelEdit.add(yTranslateSlider);
		panelEdit.add(yTranslateSliderToolsPanel);
		
		yTranslateSlider.addChangeListener(new ChangeListener() {
			
			@Override
			public void stateChanged(ChangeEvent e) {
				yTranslateSliderValue.setText("    Y: " + new Float(yTranslateSlider.getValue()/10.0f).toString());
			}
		});
		
		zTranslateSliderLeftButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(zTranslateSlider.getValue()>-200)
					zTranslateSlider.setValue(zTranslateSlider.getValue()-1);
			}
		});
		
		zTranslateSliderRightButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(zTranslateSlider.getValue()<200)
					zTranslateSlider.setValue(zTranslateSlider.getValue()+1);
			}
		});
		
		zTranslateSlider.setToolTipText("Z");
		zTranslateSliderToolsPanel.setPreferredSize(new Dimension(200, 20));
		zTranslateSliderToolsPanel.setLayout(new GridLayout(1, 3));
		zTranslateSliderToolsPanel.add(zTranslateSliderLeftButton);
		zTranslateSliderToolsPanel.add(zTranslateSliderRightButton);
		zTranslateSliderToolsPanel.add(zTranslateSliderValue);
		panelEdit.add(zTranslateSlider);
		panelEdit.add(zTranslateSliderToolsPanel);
		
		zTranslateSlider.addChangeListener(new ChangeListener() {
			
			@Override
			public void stateChanged(ChangeEvent e) {
				zTranslateSliderValue.setText("    Z: " + new Float(zTranslateSlider.getValue()/10.0f).toString());
			}
		});
		
		panelEdit.add(new JLabel("SCALE"));
		
		scaleSliderLeftButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(scaleSlider.getValue()>1)
					scaleSlider.setValue(scaleSlider.getValue()-1);
			}
		});
		
		scaleSliderRightButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(scaleSlider.getValue()<1000)
					scaleSlider.setValue(scaleSlider.getValue()+1);
			}
		});
		
		scaleSlider.setToolTipText("X");
		scaleSliderToolsPanel.setPreferredSize(new Dimension(200, 20));
		scaleSliderToolsPanel.setLayout(new GridLayout(1, 3));
		scaleSliderToolsPanel.add(scaleSliderLeftButton);
		scaleSliderToolsPanel.add(scaleSliderRightButton);
		scaleSliderToolsPanel.add(scaleSliderValue);
		panelEdit.add(scaleSlider);
		panelEdit.add(scaleSliderToolsPanel);
		
		scaleSlider.addChangeListener(new ChangeListener() {
			
			@Override
			public void stateChanged(ChangeEvent e) {
				scaleSliderValue.setText("    X: " + new Float(scaleSlider.getValue()/10.0f).toString());
			}
		});
		
		polyModePointButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				polyModePointButton.setEnabled(false);
				polyModeLineButton.setEnabled(true);
				polyModeFillButton.setEnabled(true);
				faceModeBackButton.setEnabled(false);
				faceModeFrontButton.setEnabled(false);
				faceModeFrontAndBackButton.setEnabled(false);
			}
		});
		
		polyModeLineButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				polyModePointButton.setEnabled(true);
				polyModeLineButton.setEnabled(false);
				polyModeFillButton.setEnabled(true);
				faceModeBackButton.setEnabled(false);
				faceModeFrontButton.setEnabled(false);
				faceModeFrontAndBackButton.setEnabled(false);
			}
		});
		
		polyModeFillButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				polyModePointButton.setEnabled(true);
				polyModeLineButton.setEnabled(true);
				polyModeFillButton.setEnabled(false);
				faceModeBackButton.setEnabled(true);
				faceModeFrontButton.setEnabled(true);
				faceModeFrontAndBackButton.setEnabled(false);
			}
		});
		
		polyModePanel.setLayout(new GridLayout(1, 3));
		polyModePanel.add(polyModePointButton);
		polyModePanel.add(polyModeLineButton);
		polyModePanel.add(polyModeFillButton);
		polyModeFillButton.setEnabled(false);
		
		panelEdit.add(polyModePanel);
		
		faceModeBackButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				faceModeBackButton.setEnabled(false);
				faceModeFrontButton.setEnabled(true);
				faceModeFrontAndBackButton.setEnabled(true);
			}
		});
		
		faceModeFrontButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				faceModeBackButton.setEnabled(true);
				faceModeFrontButton.setEnabled(false);
				faceModeFrontAndBackButton.setEnabled(true);
			}
		});
		
		faceModeFrontAndBackButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				faceModeBackButton.setEnabled(true);
				faceModeFrontButton.setEnabled(true);
				faceModeFrontAndBackButton.setEnabled(false);
			}
		});
		
		faceModePanel.setLayout(new GridLayout(1, 3));
		faceModePanel.add(faceModeBackButton);
		faceModePanel.add(faceModeFrontButton);
		faceModePanel.add(faceModeFrontAndBackButton);
		faceModeFrontAndBackButton.setEnabled(false);
		panelEdit.add(faceModePanel);
		
		panelEdit.add(resetCameraButton);
		panelEdit.add(resetObjectButton);
		
		for(int i = 0; i<23; i++) {
			dataLines[i] = new JLabel();
			panelInfo.add(dataLines[i]);
		}
		
		
		helpLabel.setText(helpText);
		panelHelp.add(helpLabel);
		
		newAction.setText("New");
		newAction.setPreferredSize(new Dimension(200, 20));		
		newAction.setEnabled(true);
		newAction.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {		
				for (int i=0; i<oknoGlowne.listaPlikow.iloscPlikow; ++i) {
					oknoGlowne.listaPlikow.listaSciezekDoPlikow_IplImage[i] = null;	
					oknoGlowne.listaPlikow.listaSciezekDoPlikow_String[i] = null;
				}
				
				oknoGlowne.listaPlikow.iloscPlikow = 0;
				
				oknoGlowne.panelMiniatur.odswierz(oknoGlowne.listaPlikow.iloscPlikow, oknoGlowne.listaPlikow.listaSciezekDoPlikow_String);
				
				przyciskImportPhotos.setText("Import photos");
				przyciskImportPhotos.setEnabled(true);
				
				przyciskThreshold.setText("Threshold");
				przyciskThreshold.setEnabled(false);
				
				przyciskDesignatePoints.setText("Designate points");
				przyciskDesignatePoints.setEnabled(false);
				
				przyciskCreatePolygons.setText("Create polygons");
				przyciskCreatePolygons.setEnabled(false);
				
				przyciskSave.setText("Save to OBJ");
				przyciskSave.setEnabled(false);
				
				oknoGlowne.panelMenu.repaint();
			}			
		});
		panelFile.add(newAction);

		
		openAction.setText("Open");
		openAction.setPreferredSize(new Dimension(200, 20));
		panelFile.add(openAction);

		
		saveAction.setText("Save");
		saveAction.setPreferredSize(new Dimension(200, 20));
		panelFile.add(saveAction);

		panelFile.add(new JSeparator());

		
		przyciskImportPhotos.setText("Import photos");
		przyciskImportPhotos.setEnabled(true);
		przyciskImportPhotos.setPreferredSize(new Dimension(200, 20));
		przyciskImportPhotos.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				new WyborKatalogu(oknoGlowne);
			}
		});
		panelFile.add(przyciskImportPhotos);

		
		przyciskThreshold.setText("Threshold");
		przyciskThreshold.setEnabled(false);
		przyciskThreshold.setPreferredSize(new Dimension(200, 20));
		przyciskThreshold.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				
				progowanie.ustawienia(oknoGlowne.listaPlikow.listaSciezekDoPlikow_IplImage, oknoGlowne.listaPlikow.iloscPlikow, oknoGlowne.listaPlikow.listaSciezekDoPlikow_String);
				
				if (progowanie.wykonanoProgowanie) {
					oknoGlowne.panelMiniatur.odswierz(oknoGlowne.listaPlikow.iloscPlikow, oknoGlowne.listaPlikow.listaSciezekDoPlikow_String);
				
					oknoGlowne.panelMenu.przyciskDesignatePoints.setEnabled(true);
					oknoGlowne.panelMenu.przyciskThreshold.setEnabled(false);
					oknoGlowne.panelMenu.przyciskThreshold.setText("Threshold   ( OK )");
					oknoGlowne.panelMenu.repaint();
				}
			}
		});
		panelFile.add(przyciskThreshold);
		
		
		przyciskDesignatePoints.setText("Designate points");
		przyciskDesignatePoints.setEnabled(false);
		przyciskDesignatePoints.setPreferredSize(new Dimension(200, 20));
		przyciskDesignatePoints.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				
				wp.oknoUstawienWyznaczaniaPunktow(oknoGlowne);
				
				if (wp.wykonanoProsty) {
					przyciskDesignatePoints.setEnabled(false);
					przyciskDesignatePoints.setText("Designate points   ( OK )");
					przyciskCreatePolygons.setEnabled(true);
					oknoGlowne.panelMenu.repaint();
				}
				
				if (wp.wykonanoRozszerzony) {
					przyciskDesignatePoints.setEnabled(false);
					przyciskDesignatePoints.setText("Designate points   ( OK )");
					przyciskCreatePolygons.setText("Create polygons   ( SKIP )");
					przyciskSave.setEnabled(true);
					oknoGlowne.panelMenu.repaint();					
				}
			
			}			
		});
		panelFile.add(przyciskDesignatePoints);
	
		
		przyciskCreatePolygons.setText("Create polygons");
		przyciskCreatePolygons.setEnabled(false);
		przyciskCreatePolygons.setPreferredSize(new Dimension(200, 20));
		przyciskCreatePolygons.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				
				faces = new Faces(wp.getNumOfVertex(), wp.getNumOfPhoto());
				try {
					faces.createTriangle();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				przyciskCreatePolygons.setEnabled(false);
				przyciskCreatePolygons.setText("Create polygons   ( OK )");
				przyciskSave.setEnabled(true);
				
			}			
		});
		panelFile.add(przyciskCreatePolygons);
		
		przyciskSave.setText("Save to OBJ");
		przyciskSave.setEnabled(false);
		przyciskSave.setPreferredSize(new Dimension(200, 20));
		przyciskSave.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				
				saveObj.zapis(oknoGlowne);
				
			}			
		});
		panelFile.add(przyciskSave);

	
		panelFile.add(new JSeparator());

		JButton exitAction = new JButton();
		exitAction.setText("Exit");
		exitAction.setPreferredSize(new Dimension(200, 20));
		exitAction.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				/* Przed zamknieciem (do zrobienia) */
				System.exit(0);
			}
		});
		panelFile.add(exitAction);
		
		for(int i=0; i<12; i++)
			panelFile.add(new JLabel());

		add(tabs);

	}
}
